package com.bc.bcapi.service;

import com.bc.bcmodel.consts.GlobalSettings;
import com.bc.commonentity.common.JsonResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.math.BigInteger;

import com.bc.bcapi.dao.T_Home_bannerMapper;
import com.bc.bcmodel.domain.T_Home_bannerModel;

/**
 * @Name T_Home_bannerService * @Description  * @Author generation * @Date 2018/11/1 21:26:35 * @Version 1.0
 **/
@Service
public class T_Home_bannerService {
    @Resource
    T_Home_bannerMapper t_Home_bannerMapper;
    @Resource
    LanguageService languageService;

    /**
     * 保存单条数据     *      * @return
     */
    public int insert(T_Home_bannerModel req) {
        return t_Home_bannerMapper.insert(req);
    }

    /**
     * 批量增加数据     *      * @return
     */
    public int insertBatch(List<T_Home_bannerModel> req) {
        return t_Home_bannerMapper.insertBatch(req);
    }

    /**
     * 根据对象属性查找满足条件的第一条数据     *      * @return
     */
    public T_Home_bannerModel findByNamedParam(T_Home_bannerModel req) {
        return t_Home_bannerMapper.findByNamedParam(req);
    }

    /**
     * 根据对象查询所有数据     *      * @return
     */
    public List<T_Home_bannerModel> getAllList(T_Home_bannerModel req) {
        return t_Home_bannerMapper.findByNamedParamList(req);
    }

    /**
     * 根据对象查询所有分页数据     *      * @return
     */
    public PageInfo<T_Home_bannerModel> getList(T_Home_bannerModel req) {
        PageHelper.startPage(req.getPage_index(), req.getPage_size());
        List<T_Home_bannerModel> list = t_Home_bannerMapper.findByNamedParamList(req);
        return new PageInfo<T_Home_bannerModel>(list);
    }

    /**
     * 更新指定对象     *      * @return
     */
    public int update(T_Home_bannerModel req) {
        return t_Home_bannerMapper.update(req);
    }

    /**
     * 删除指定数据     *      * @return
     */
    public int delete(BigInteger id) {
        return t_Home_bannerMapper.delete(id);
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    public long count(T_Home_bannerModel req) {
        return t_Home_bannerMapper.count(req);
    }

    public JsonResult getHomeBanner(HttpServletRequest request, HttpServletResponse response) {
        String language =
                languageService.getCurrentLanguage(request, response, GlobalSettings.LANGUAGE);
        T_Home_bannerModel t_home_bannerModel = new T_Home_bannerModel();
        t_home_bannerModel.setLanguage_data(language);
        List<T_Home_bannerModel> list =
                t_Home_bannerMapper.getHomeBanner(t_home_bannerModel);
        return new JsonResult(list);
    }
}